<!--种猪  免疫-->
<template>
    <el-card shadow="never" class="aui-card--fill">
        <el-form :inline="true" :model="formInline">
            <el-form-item label="舍号">
                <el-input v-model="formInline.shehao" placeholder="舍号" size="small" clearable></el-input>
            </el-form-item>
            <el-form-item label="防治项目">
                <el-input v-model="formInline.name" placeholder="防治项目" size="small" clearable></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit" size="small">查询</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="warning" size="small" @click="showDialog">新增</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="danger" size="small" @click="batchDelete">批量删除</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="info" size="small">导出</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border @selection-change="handleSelectionChange"
                  :row-class-name="tableRowClassName">
            <el-table-column type="selection" width="55" align="center">
            </el-table-column>
            <el-table-column prop="date" label="防治日期" align="center">
            </el-table-column>
            <el-table-column prop="" label="症状" align="center">
            </el-table-column>
            <el-table-column prop="" label="检测结果" align="center">
            </el-table-column>
            <el-table-column prop="" label="舍号" align="center">
            </el-table-column>
            <el-table-column prop="" label="栏位" align="center">
            </el-table-column>
            <el-table-column prop="" label="防治头数" align="center">
            </el-table-column>
            <el-table-column prop="" label="用药" align="center">
            </el-table-column>
            <el-table-column prop="" label="用量" align="center">
            </el-table-column>
            <el-table-column prop="" label="防治方式" align="center">
            </el-table-column>
            <el-table-column prop="" label="恢复情况" align="center">
            </el-table-column>
            <el-table-column prop="time" label="休药期（天）" align="center" width="100">
            </el-table-column>
            <el-table-column prop="" label="操作人" align="center">
            </el-table-column>
            <el-table-column prop="" label="备注" align="center">
            </el-table-column>
            <el-table-column label="操作" align="center" width="160">
                <template slot-scope="scope">
                    <el-button size="mini" type="primary" @click="handleEdit(scope.row)">修改</el-button>
                    <el-button size="mini" type="danger" @click="deleteData(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <Pagination @sizeChange="sizeChange" @currentChange="currentChange" :total="total" :currentPage="currentPage"/>
        <Dialog ref="refDialog" @updateDialog="updateDialog"></Dialog>
    </el-card>
</template>

<script>
// import mixinViewModule from '@/mixins/view-module'
import Dialog from './preventive-treatment-dialog.vue'
import Pagination from "@/components/pagination.vue";

export default {
    components: {
        Pagination,
        Dialog
    },
    // mixins: [mixinViewModule],
    data() {
        return {
            mixinViewModuleOptions: {
                // getDataListURL: '/history/deadmortality/page',
                // getDataListIsPage: true,
                // exportURL: '/history/deadmortality/export',
                // deleteURL: '/history/deadmortality',
                // deleteIsBatch: true
            },
            tableData: [
                {
                    id: 1,
                    date: '2023/12/2',
                    project: '猪瘟',
                    time: ''
                },
                {
                    id: 1,
                    date: '2023/12/2',
                    project: '猪瘟',
                    time: 0
                },
                {
                    id: 1,
                    date: '2023/12/2',
                    project: '猪瘟',
                    time: 33
                }
            ],
            currentPage: 1,//默认显示第一页
            pageSize: 10,//默认每页显示5条数据
            total: 100,//总数据条数
            manyArr: [],
            formInline: {
                shehao: '',
                pigHerdCategory: '',
                name: ''
            },
            object: [{
                value: '生长猪',
                label: '生长猪'
            }, {
                value: '种猪',
                label: '种猪'
            }],
        }
    },
    mounted() {
        // this.getData();
    },
    methods: {
        tableRowClassName({row, rowIndex}) {
            if (row.time === "" || row.time === 0) {
                return '';
            } else {
                return 'success-row';
            }
        },
        // 列表的数据
        getData() {
            this.$http.get(`/kk`).then(({data: res}) => {
                if (res.code !== 0) {
                    return this.$message.error(res.msg);
                }
                this.tableData = res.data
            }).catch(() => {
            });
        },
        // 新增
        showDialog() {
            this.$refs.refDialog.dialogVisible = true
        },
        // 编辑
        handleEdit(row) {
            this.$refs.refDialog.dialogVisible = true
            this.$refs.refDialog.immunityForm = {...row};
        },
        // 每页条数
        sizeChange(val) {
            this.currentPage = 1;
            this.pageSize = val;
        },
        // 当前页
        currentChange(val) {
            this.currentPage = val
        },
        updateDialog() {

        },
        onSubmit() {
            console.log('submit!', this.formInline);
        },
        handleSelectionChange(val) {
            this.manyArr = val.map(it => it.id)
            console.log(this.manyArr, 'this.manyArr')
        },
        // 批量删除按钮
        batchDelete() {
            this.deleteData()
        },
        // 删除接口----------------
        deleteData(id) {
            console.log('id', id)
            if (this.manyArr.length > 0 || id) {
                this.$confirm(`确定要删除数据吗？`, "提示",
                    {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    }
                ).then(() => {
                    this.$http.delete(`/stock/stockin`, {data: id ? [id] : this.manyArr}).then(({data: res}) => {
                        if (res.code != 0) {
                            return this.$message.error(res.msg)
                        }
                        this.$message({
                            type: "success",
                            message: "删除成功!"
                        });
                        this.getDataList();
                    });
                }).catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除"
                    });
                });
            } else {
                this.$message({
                    type: "info",
                    message: "请先进行选择!"
                });
            }
        },
    }
}
</script>
<style>
.el-table .success-row {
    background: #fbb7b7;
}
</style>
